package com.example.neusoft.yuejian_12.Activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import com.example.neusoft.yuejian_12.Adapter.ClubSearchAdapter;
import com.example.neusoft.yuejian_12.JavaBean.Club;
import com.example.neusoft.yuejian_12.Listener.SearchListener;
import com.example.neusoft.yuejian_12.Model.ClubModel;
import com.example.neusoft.yuejian_12.R;

import java.util.List;

/**
 * Created by admin on 2017/10/25.
 */

public class ClubSearchActivity extends Activity {

    private ImageButton back;
    private View view = null;
    private ClubSearchAdapter adapter = null;
    List<Club> clubListsearch = null;
    private Button button_search;
    private EditText keyword;
    private RecyclerView recycleviewclub;

    private Context getcontext() {
        return this;
    }

    SearchListener searchListener = new SearchListener() {
        @Override
        public void onResponse(List<Club> listBean) {
            recycleviewclub.setAdapter(new ClubSearchAdapter(getcontext(), (List<Club>) listBean));
            adapter.getSearchClub(clubListsearch);
            adapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {

        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_club);
        initRecyclerView(view);

        back= (ImageButton) findViewById(R.id.back);
        keyword = (EditText) findViewById(R.id.ckeyword);
        button_search = (Button) findViewById(R.id.btn_search);

        button_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ClubModel model = new ClubModel();
                final String club_name = keyword.getText().toString();
                model.getsearch(club_name,searchListener);
            }

        });

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    public  void initRecyclerView(View view){
        recycleviewclub=(RecyclerView) findViewById(R.id.recycleview_search);
        recycleviewclub.setLayoutManager(new LinearLayoutManager(this));
        recycleviewclub.setItemAnimator(new DefaultItemAnimator());
        adapter = new ClubSearchAdapter(this,clubListsearch);
    }
}
